package com.ruoyi.web.controller.crm;

import com.bonuo.crm.domain.Inform;
import com.bonuo.crm.domain.Newspaper;
import com.bonuo.crm.service.InformService;
import com.bonuo.crm.service.NewspaperService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//通知controller
@RestController
@RequestMapping("/crm/inform")
@Api(tags = "通知")
public class InformController extends BaseController {
    @Autowired
    private InformService informService;
    @Autowired
    private NewspaperService newSpaperService;

    //查询所有通知信息
    @GetMapping("/list")
    @ApiOperation(value = "查询所有信息",httpMethod = "GET")
    public AjaxResult list(Inform inform){
        PageHelper.startPage(inform.getPageNum(),inform.getPageSize());
        List<Inform> informList = informService.selectInformList(inform);
        return AjaxResult.success(new PageInfo<>(informList));
    }

    //根据周报ID查询周报信息
    @GetMapping("/selectNewspaperById")
    @ApiOperation(value = "根据周报ID查询周报信息",httpMethod = "GET")
    public AjaxResult selectNewspaperById(Integer id){
        Newspaper newspaper = newSpaperService.selectNewspaperById(id);
        return AjaxResult.success(newspaper);
    }

    //查询未通知和为阅读的所有消息
    @GetMapping("/selectNoNoticeInfo")
    @ApiOperation(value = "查询未通知或未阅读的所有消息",httpMethod = "GET")
    public AjaxResult selectNoNoticeInfo(Inform inform){
        List<Inform> informList = informService.selectNoNoticeInfo(inform);
        return AjaxResult.success(informList);
    }

    //修改未通知信息
    @PutMapping("/update")
    @ApiOperation(value = "修改未通知信息",httpMethod = "PUT")
    public AjaxResult update(@RequestBody Inform inform){
        Integer i = informService.updateInform(inform);
        return toAjax(i);
    }

    //一键修改该用户所有已读信息
    @PutMapping("/updateAll")
    @ApiOperation(value = "修改该用户所有已读信息",httpMethod = "PUT")
    public AjaxResult updateAll(@RequestBody Inform inform){
        Integer i = informService.updateInformAll(inform);
        return toAjax(i);
    }

}
